/*
 * @Description: 
 * @Version: 2.0
 * @Autor: ftt
 * @Date: 2022-03-23 15:56:16
 * @LastEditors: TT
 * @LastEditTime: 2023-03-08 22:02:36
 */

import 'package:easy_refresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:hzy_normal_widget/hzy_normal_utils.dart';
import 'package:ttcomment/ttcomment.dart';

abstract class NormalGetxController extends GetxController {
  var pageState = PageState.initializedState.obs;

  var isshowloading = false.obs;
  var sizew = 0.0.obs;

  configsiezw(double maxw) {
    sizew.value = maxw;
  }

  /// 配置点击失败界面 刷线方法
  configreload() {}
}

abstract class NormalGetxListController extends NormalGetxController
    implements AbstractNetWork {
  EasyRefreshController? refreshController;

  bool controlFinishLoad = true;

  bool controlFinishRefresh = true;
  int page = 1;

  @override
  void onInit() {
    super.onInit();
    refreshController = EasyRefreshController(
      controlFinishLoad: controlFinishLoad,
      controlFinishRefresh: controlFinishRefresh,
    );
  }

  // 下啦刷新触发事件
  configRefresh() async {
    page = 1;
    getnetworkdata(type: 1, info: configNetWorkParmas());
  }

  // 上啦加载更多触发事件
  configLoading() async {
    page++;
    getnetworkdata(type: 2, info: configNetWorkParmas());
  }

  /// 网络请求 参数方法
  @override
  Map<String, dynamic>? configNetWorkParmas() {
    return null;
  }

  /// 网络请求数据
  @override
  void getnetworkdata({int? type, Map<String, dynamic>? info}) async {}

  /// 通过数据 进行 pagestate 转换
  configListPageState({
    required int allNum,
    required int networkNum,
  }) {
    return CommentTools.configPageState(
      allNum: allNum,
      networkNum: networkNum,
    );
  }

  /// 结束刷新
  void endRefresh({int? type, PageState? state}) {
    pageState.value = HzyNormalUtils.configEndRefresh(
      type: type,
      state: state,
      refreshController: refreshController,
    );
  }
}
